package com.ruoyi.web.controller.background;

import com.ruoyi.background.domain.AppWorkTeam;
import com.ruoyi.background.service.IAppWorkTeamService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 健步走队伍Controller
 *
 * @author susu
 * @date 2024-09-04
 */
@RestController
@RequestMapping("/applet/workTeam")
public class AppWorkTeamController extends BaseController {
    @Autowired
    private IAppWorkTeamService appWorkTeamService;

    /**
     * 查询健步走队伍列表
     */
    @PreAuthorize("@ss.hasPermi('applet:workTeam:list')")
    @GetMapping("/list")
    public TableDataInfo list(AppWorkTeam appWorkTeam) {
        startPage();
        List<AppWorkTeam> list = appWorkTeamService.selectAppWorkTeamList(appWorkTeam);
        return getDataTable(list);
    }

    /**
     * 导出健步走队伍列表
     */
    @PreAuthorize("@ss.hasPermi('applet:workTeam:export')")
    @Log(title = "健步走队伍", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AppWorkTeam appWorkTeam) {
        List<AppWorkTeam> list = appWorkTeamService.selectAppWorkTeamList(appWorkTeam);
        ExcelUtil<AppWorkTeam> util = new ExcelUtil<AppWorkTeam>(AppWorkTeam.class);
        util.exportExcel(response, list, "健步走队伍数据");
    }

    /**
     * 获取健步走队伍详细信息
     */
    @PreAuthorize("@ss.hasPermi('applet:workTeam:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(appWorkTeamService.selectAppWorkTeamById(id));
    }

    /**
     * 新增健步走队伍
     */
    @PreAuthorize("@ss.hasPermi('applet:workTeam:add')")
    @Log(title = "健步走队伍", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AppWorkTeam appWorkTeam) {
        return toAjax(appWorkTeamService.insertAppWorkTeam(appWorkTeam));
    }

    /**
     * 修改健步走队伍
     */
    @PreAuthorize("@ss.hasPermi('applet:workTeam:edit')")
    @Log(title = "健步走队伍", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AppWorkTeam appWorkTeam) {
        return toAjax(appWorkTeamService.updateAppWorkTeam(appWorkTeam));
    }

    /**
     * 删除健步走队伍
     */
    @PreAuthorize("@ss.hasPermi('applet:workTeam:remove')")
    @Log(title = "健步走队伍", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(appWorkTeamService.deleteAppWorkTeamByIds(ids));
    }
}
